import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xr_base/dimens.dart';
import 'package:xr_base/view_util.dart';

import '../models/banner.dart';
import '../provider/home_provider.dart';
import 'keepalive_wrapper.dart';

class BannerWidget extends StatelessWidget {
  const BannerWidget({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Consumer<HomeProvider>(builder: (
      BuildContext context,
      HomeProvider value,
      Widget? child,
    ) {
      return Container(
        width: double.infinity,
        height: Dimens.dn_180,

        /// 117
        color: Colors.transparent,
        child: ClipRRect(
          borderRadius: BorderRadius.circular(Dimens.dn_10),
          child: Swiper(
            itemBuilder: (BuildContext context, int index) {
              final BannerMo _bannerMo = value.banners[index];
              // debugPrint('---😆😆_bannerMo.tempImageUrl:${_bannerMo.tempImageUrl}😆😆---');
              return KeepAliveWrapper(
                child: cachedImage(_bannerMo.tempImageUrl, fit: BoxFit.cover),
              );
            },
            itemCount: value.banners.length,
            autoplay: true,
            duration: 800,
            pagination: SwiperPagination(),
          ),
        ),
      );
    });
  }
}
